#include "DynLib.h"
#include "../fuLogger.h"

BEGIN_NAMESPACE_CPPX

DynLib::DynLib( const std::string& name )
{
	m_hInst     = NULL;
	m_IsLoaded  = false;
	setName(name);
	Load(name);
}

DynLib::~DynLib( void )
{
	Unload();
}

void DynLib::Load(const std::string & name)
{
	m_hInst = (HINSTANCE)LoadLibraryA(getName().c_str());
	if( !m_hInst ){
		return;
	}
	m_IsLoaded = true;
}

void DynLib::Unload(void)
{
	if (m_IsLoaded){
		if( !FreeLibrary( m_hInst ) ){
			return;
		}
	}
	m_IsLoaded = false;
}

void* DynLib::GetSymbol( const char * strFuncName ) const throw()
{
	if (m_IsLoaded)
		return (void*)GetProcAddress( m_hInst, strFuncName );
	return NULL;
}

bool DynLib::IsLoaded( void ) const
{
	return m_IsLoaded;
}

END_NAMESPACE_CPPX
